
//
//  MyNavigationBar.m
//  Cooking
//
//  Created by ZhiPeng.Y on 15/8/31.
//  Copyright (c) 2015年 ZP.Y. All rights reserved.
//

#import "MyNavigationBar.h"
#import "AppMacro.h"

@interface MyNavigationBar ()

@property (retain, nonatomic) UIView *navigationBar;

@end

@implementation MyNavigationBar

- (void)dealloc {
    [_titleLabel release];
    [_navigationBar release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView {
    self.navigationBar = [[UIView alloc] init];
    _navigationBar.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:125 / 255.0 blue:67 / 255.0 alpha:1];
    [self addSubview:_navigationBar];
    [_navigationBar release];

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(5, 19,25, 25)];
//    button.backgroundColor = [UIColor blackColor];
    [button setBackgroundImage:[UIImage imageNamed:@"iconfont-jiantouzuo.png"] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [_navigationBar addSubview:button];
    [button release];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 19, WIDTH - 60, 25)];
    _titleLabel.textAlignment = NSTextAlignmentCenter;
//    _titleLabel.backgroundColor = [UIColor grayColor];
    _titleLabel.textColor = [UIColor whiteColor];
    [_navigationBar addSubview:_titleLabel];
    [_titleLabel release];
    
//    
//    UIButton *rightbutton = [[UIButton alloc] initWithFrame:CGRectMake(WIDTH - 30, 19,25, 25)];
//    //    button.backgroundColor = [UIColor blackColor];
//    [rightbutton setBackgroundImage:[UIImage imageNamed:@"iconfont-shoucang-5"] forState:UIControlStateNormal];
//    [rightbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [rightbutton addTarget:self action:@selector(rightButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//    [_navigationBar addSubview:rightbutton];
//    [rightbutton release];
}

- (void)buttonAction:(id)sender {
    [self.delegate clickButton:sender];
}
//
//- (void)rightButtonAction:(id)sender {
//    [self.delegate clickRightButton:sender];
//}
- (void)layoutSubviews {
    [super layoutSubviews];
    _navigationBar.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
